/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.account;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.Organization;
import apus.entity.Person;
import apus.entity.Subscriber;
import apus.persistence.OrganizationDAO;
import apus.persistence.PersonDAO;
import apus.persistence.SubscriberDAO;
import apus.services.ServiceLocator;

/**
 *
 * @author Admin
 */
public class AccountCreateAction implements Action {

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        int sub_id = Integer.parseInt(request.getParameter("sub_id"));
        int subscriberType = Integer.parseInt(request.getParameter("sub_type"));
        Subscriber subscriber;
        SubscriberDAO dao;
                if (subscriberType == 0) {
                    dao = ServiceLocator.getService(PersonDAO.class);
                    subscriber = (Person)dao.read(sub_id);
                } else {
                    dao = ServiceLocator.getService(OrganizationDAO.class);
                    subscriber = (Organization) dao.read(sub_id);
                }
        request.setAttribute("subscriber", subscriber);
        request.setAttribute("subscriberType", subscriberType);
        return ActionResult.forward("/WEB-INF/View/AccountView/CreateAccountView.jsp");
    }

    @Override
    public String getName() {
        return "account.create";
    }
}
